package com.jrx.anytxn.transaction.controller.api;

import com.jrx.anytxn.common.exception.TxnException;
import com.jrx.anytxn.i18n.response.TxnRespResult;
import com.jrx.anytxn.transaction.dto.loan.GlInterfaceReq;
import com.jrx.anytxn.transaction.dto.loan.GlInterfaceRes;
import com.jrx.anytxn.transaction.dto.loan.RecordGlInterfaceReq;
import com.jrx.anytxn.transaction.dto.loan.RecordGlInterfaceRes;
import com.jrx.anytxn.transaction.service.IGlInterfaceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@Api(tags = "总账流水相关接口")
@RestController
@RequestMapping(value = "/api/transaction/gl")
public class GlInterfaceController {

    private static final Logger logger = LoggerFactory.getLogger(GlInterfaceController.class);

    @Autowired
    private IGlInterfaceService glInterfaceService;


    @ApiOperation(value = "生成总账流水", notes = "生成总账流水API")
    @PostMapping(value = "/buildTlGlInterfaceInfo")
    public TxnRespResult<GlInterfaceRes> buildTlGlInterfaceInfo(@Valid @RequestBody GlInterfaceReq glInterfaceReq) throws TxnException {
        logger.info("开始生成总账流水，产品ID{}",glInterfaceReq.getLoanProductId());
        TxnRespResult<GlInterfaceRes> result = new TxnRespResult<>();
        result.getSuccess(glInterfaceService.buildTlGlInterfaceInfo(glInterfaceReq));
        return result;
    }

    @ApiOperation(value = "总账流水记账", notes = "总账流水记账API")
    @PostMapping(value = "/recordGlInterface")
    public TxnRespResult<RecordGlInterfaceRes> recordGlInterface(@Valid @RequestBody RecordGlInterfaceReq recordGlInterfaceReq) throws TxnException {
        logger.info("开始总账流水记账，贷款ID{}",recordGlInterfaceReq.getLoanId());
        TxnRespResult<RecordGlInterfaceRes> result = new TxnRespResult<>();
        result.getSuccess(glInterfaceService.buildTlGlInterfaceInfo(recordGlInterfaceReq));
        return result;
    }

}
